﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SevenZip;

namespace Steam_Backup
{
    public partial class FrmMain : Form
    {
        private Settings m_settings = new Settings();

        public FrmMain()
        {
            InitializeComponent();
            m_settings = Settings.LoadSettings();
            UpdateGameList();
        }



        double m_dCurrentProgress = 0.0;

        private void button1_Click(object sender, EventArgs e)
        {
            FrmAddGame frmAddGame = new FrmAddGame();
            if (frmAddGame.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                GameEntry newGame = frmAddGame.GameEntry;
                m_settings.AddGame(newGame);
                m_settings.SaveSettings();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {

            //tmp.CompressFiles("test.7z", @"D:\steam\steamapps\episode two maps.gcf");
        }

        void tmp_Compressing(object sender, ProgressEventArgs e)
        {
            m_dCurrentProgress += e.PercentDelta;
            //byte euh = e.PercentDelta;// / e.PercentDone;
            prgCurrentProgress.Value = (int)m_dCurrentProgress;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            FrmAddGame frmAddGame = new FrmAddGame();
            frmAddGame.Show();
        }

        private void btnOptions_Click(object sender, EventArgs e)
        {
            FrmOptions frmOptions = new FrmOptions(m_settings);
            frmOptions.ShowDialog();
        }

        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            m_settings.SaveSettings();
        }

        private void UpdateGameList()
        {
            foreach (GameEntry entry in m_settings.GameEntries)
            {
                string[] infos = new string[] { entry.GameTitle, entry.LastBackup };
                ListViewItem item = new ListViewItem(infos);
                item.Tag = entry;
                lstGames.Items.Add(item);
            }
        }

        private void btnBackup_Click(object sender, EventArgs e)
        {
            List<GameEntry> gameEntries = new List<GameEntry>();

            BackupGames(gameEntries);
        }

        private void BackupGames(List<GameEntry> gameEntries)
        {
            FrmBackup frmBackup = new FrmBackup(m_settings.GameEntries, m_settings);
            frmBackup.ShowDialog();
        }
    }
}
